%This file computes the gains from industrial policy from max reallocation,
%using the Harberger formula plus weighted average value added shares.

clear all;

%digits(64);

K=32; %number of sectors
K_man=15;    %number of manufacturing sectors

%Importing data on average value added shares shares
A=importdata('avg_va_shares_no_int.csv');

%Importing elasticities
B=importdata('sim_params_no_int.csv');

va_shares = A(:,2);
%For each calculation, we a) pick the sector with the max SE, b) set the
%reallocation term for that sector to the max possible, c) set the
%realloation terms of the other sectors to the negative of the initial
%share.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Baseline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Parameter vectors
h_gamma = [zeros(2,1);B(:,1);zeros(K-2-K_man,1)]; %Heterogeneous scale elasticities, non-manufacturing set to zero

%Maximum SE
[se_max se_pos]=max(h_gamma)
%Reallocation terms
reallocation = -va_shares;  
reallocation(se_pos)=1-va_shares(se_pos)
%Harberger formula
max_reallocation_base = 1/2*sum(h_gamma.*reallocation)


max_reallocation=[max_reallocation_base]
csvwrite('max_reallocation.csv',max_reallocation);



